/*
Kiwi Editor is a framework for building WYSIWYG web editors.
Copyright (C) 2011  Roosevelt de Lima Sardinha

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

Contact the author at roosevelt1@gmail.com (Roosevelt) 
*/

/* Image */
function image(){	

    this.showProperties = function(){
	   this.tabId = this.propertyBox.addTab("Image");
   	   this.propertyBox.addProperty(this.tabId, 0, 0, 'file', 'FileUpload', this, {
	   		label: 'File',
			help: 'Select the file, then click "Send" to upload the image.'
	   });  
    };
    
    this.setProperty = function(property, value){
        // Changes the property of  this object setting it to value.
		 switch (property) {
			case 'file':
				this.img.src = value;
				break;
			case 'width':
				this.img.style.width = value;
				break;	
			case 'height':
				this.img.style.height = value;			
				break;
            default:
                break;
        }
    };
    
    this.getProperty = function(property){
        // Gets the property of  this object
        switch (property) {
			case 'file':
				return this.img.src;
				break;
			case 'width':
				return this.img.style.width;
				break;
			case 'height':
				return this.img.style.height;
				break;
            default:
                break;
        }
    };
    
    this.JSON = function(){
        var EO_JSON = {
			file: this.getProperty('file'),
			width: this.getProperty('width'),
			height: this.getProperty('height')
		};
        return EO_JSON;
    }
	
	this.HTML = function(){
		var html = "<img src=\"" + this.getProperty("file") + "\"  style=\"position:absolute; top: " + this.getProperty('top') + "; left: "+ this.getProperty('left') + ";" + 
		" width: "+ this.getProperty('width')+"; height: "+ this.getProperty('height')+"; \">";
		
		return html;
	}
    
    this.help = "A movable and resizabe image.";
	
	this.objectList = new Array();
	this.selectorList = new Array();
	
    this.init = function(){            
		this.objectList.push('img');
		this.selectorList.push('img');
	  
		var img = document.createElement('img');
		img.src = APP_HOME + "js/tools/image/image.png";
		img.style.width = '50px';
		img.style.height = '50px';
		img.style.cursor = 'move';
		this.img = img;
		
		var thisObject = this;
		this.onSelect = function(){
			$('#' + this.img.id).resizable({
			stop:  function(event,ui){
				thisObject.EOM.correctPosition(thisObject.id);
			},			
			containment:'#' + this.EOM.editionArea.id, 
			minWidth: 100, 
			minHeight: 50
			});
		}
    }
}
